// 引入axios模块，用于请求数据
import request from '../tools/index.js'
// 定义请求各种数据的方法，并暴露出去
export function sendCode (params) {
  return request.get('/user/sendMsg', { params })
}
export function register (params) {
  return request.post('/user/register', params)
}
export function login (params) {
  return request.get('/user/login', { params })
}
export function getPro (params) {
  return request.get('/pro/page', { params })
}
export function getDetail (params) {
  return request.get('/pro/onePro', { params })
}
export function getBanner () {
  return request.get('/banner')
}
export function getNav () {
  return request.get('/pro/column')
}
// params是axios发送数据时的语法
export function getCart (params) {
  return request.get('/cart', { params })
}
export function addCart (params) {
  return request.post('/cart/add', params)
}
export function updateCartNum (params) {
  return request.post('/cart/updateNum', params)
}
export function delCart (params) {
  return request.post('/cart/del', params)
}
export function updateFlag (params) {
  return request.post('/cart/updateFlag', params)
}
export function updateAllFlag (params) {
  return request.post('/cart/updateAllFlag', params)
}
export function addOrder (params) {
  return request.post('/order/add', params)
}
export function getOrder (params) {
  return request.get('/order', { params })
}
export function payOrder (params) {
  return request.post('/order/pay', params)
}
export function getOrderdetail (params) {
  return request.get('/order/detail', { params })
}
export function getSearch (params) {
  return request.get('/search', { params })
}
export function addSearch (params) {
  return request.post('/search/add', params)
}
export function delSearch (params) {
  return request.post('/search/del', params)
}
export function searchPro (params) {
  return request.get('/pro/search', { params })
}
export function getColumn () {
  return request.get('/pro/column')
}
export function getColumnBrand (params) {
  return request.get('/pro/brand', { params })
}
export function getColumnBrandList (params) {
  return request.get('/pro/brandlist', { params })
}
export function getUserMsg (params) {
  return request.get('/user/getUser', { params })
}
export function setUserMsg (params) {
  return request.post('/user/setUser', params)
}
export function getAddress (params) {
  // 这里在使用promise+延时器,模拟真实的后端请求数据的操作
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve([{
        id: '1',
        name: '顾士成',
        tel: '13000000000',
        address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室',
        isDefault: true
      }])
    }, 10)
  })
}
export function getCoupon (params) {
  // 这里在使用promise+延时器,模拟真实的后端请求数据的操作
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        available: 1,
        condition: '无使用门槛\n最多优惠12元',
        reason: '',
        value: 3000,
        name: '优惠券名称',
        startAt: 1489104000,
        endAt: 1514592000,
        valueDesc: '30.0',
        unitDesc: '元'
      })
    }, 10)
  })
}

export function wxPay (params) {
  return request.get('/order/wxPay', { params })
}
